﻿using CPPEI.Coolzon.Common;
using CPPEI.Coolzon.Service.Contract;
using CPPEI.Coolzon.UI.Views.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI.Views.EventProxies
{
    public class RespSwitchSolutionHandler : BaseResponseHandler<RespSwitchSolutionData>
    {
        protected override void OnHandle(RemoteEventProxy remoteEventProxy, ServiceProxy.MainServiceRef.Response response, RespSwitchSolutionData responseData)
        {
            if (string.Equals(UIContext.Current.AppType, "DISPLAYAPP", StringComparison.CurrentCultureIgnoreCase))
            {
                if (UIContext.Current.IsLoadingSolution)
                {
                    //展示端正在加载方案时，不执行操作
                    Coolzon.Common.Logger.WarningToTag("RespSwitchSolution", "接收到RespSwitchSolutionData数据要求切换到方案：{0}，但是本地正在加载方案，不执行操作", responseData.SolutionName);
                    return;
                }
            }
            if (remoteEventProxy.RenderView != null
            && remoteEventProxy.RenderView.Solution != null
            && string.Equals(responseData.SolutionName, remoteEventProxy.RenderView.Solution.Name))
            {
                Coolzon.Common.Logger.WarningToTag("RespSwitchSolution", "接收到RespSwitchSolutionData数据要求切换到方案：{0}，但是和本地的方案一致，不执行操作", responseData.SolutionName);
                return;
            }
            Coolzon.Common.Logger.InfoToTag("RespSwitchSolution", "接收到RespSwitchSolutionData数据要求切换到方案：{0}", responseData.SolutionName);

            CPPEI.Coolzon.Event.UI.UISwitchSolutionEvent @event = new CPPEI.Coolzon.Event.UI.UISwitchSolutionEvent(responseData.SolutionName);
            CPPEI.Coolzon.Event.UI.UIEventBus.PublishAsync(@event);
        }
    }
}
